home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
grunda.exe
/
GRUNDA.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-05-31
|
8KB
|
423 lines
/***********************************************************\
* Joe Walsh Presents: *
* *
* Grunda IBM *
* *
* Grunda is freeware, and in the public domain. *
* *
* Last Update: 05/31/91 *
\***********************************************************/
#include "joy.h"
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#define H '\x02' /* The Human's Icon...a happy face */
#define G '\x0C' /* Grunda's Icon */
#define W '\xDB' /* The Wall Character */
#define L '\xFB' /* The Lever Character */
#define K '\xEC' /* The Security Pass Character */
char e=0; /* End Game Flag Variable */
char button=0; /* Button 1 Variable */
char buttonb=0; /* Button 2 Variable */
char level=0; /* Level Currently Being Played (0-9) */
char dont=0; /* Game Opening Avoidance Variable */
char w=0; /* Player Won Flag Variable */
char c=0; /* Getch Storage Variable */
char pass=0; /* Security Pass Variable */
char echs=0; /* pass x value */
char why=0; /* pass y value */
char a=0; /* grunda's x value/location */
char b=0; /* grunda's y value/location */
char am=0; /* grunda's proposed x movement */
char bm=0; /* grunda's proposed y movement */
char x=0; /* human's x value/location */
char y=0; /* human's y value/location */
char wx=0; /* lever's x value/location */
char wy=0; /* lever's y value/location */
char xm=0; /* human's proposed x movement */
char ym=0; /* human's proposed y movement */
int keymin=0; /* the minimum y value recorded on the joystick */
int keymax=0; /* the maximum y value recorded on the joystick */
int joymin=0; /* the minimum x value recorded on the joystick */
int joymax=0; /* the maximum x value recorded on the joystick */
int joy=0; /* the joystick's x value read at the current time */
int key=0; /* the joystick's y value read at the current time */
int snd=0; /* Sound Variable */
int p=0; /* counter variable for wait loop */
main(void)
{
randomize();
_setcursortype(_NOCURSOR);
if (dont==0)
{
title();
center();
}
draw();
while ((e != 1) && (w!=1))
{
game();
}
if (e!=1){
gotoxy(10,10);
puts("You Won!!!!!");
}
do {
button=get_joy_button(0);
buttonb=get_joy_button(1);
} while ((button!=1) && (buttonb!=1));
if (buttonb==1)
{
e=0;
dont=1;
level=0;
pass=0;
w=0;
main();
}
if (button==1)
{
_setcursortype(_NORMALCURSOR);
clrscr();
nosound();
exit(0);
}
return 0;
}
title(void)
{
clrscr();
gotoxy(35, 10);
puts("Grunda");
gotoxy(32, 12);
puts("By Joe Walsh");
gotoxy(1,24);
puts("Press Button To Begin Game");
do {
button=get_joy_button(0);
} while (button!=1);
button=0;
return;
}
center(void)
{
clrscr();
gotoxy(10,10);
puts("Would you like sound? (Y/N)");
while (snd==0)
{
c=getch();
if (c=='\0')
{
c=getch();
}
switch(c)
{
case 89: snd=1;
break;
case 121: snd=1;
break;
case 78: snd=2;
break;
case 110: snd=2;
break;
default: putchar('\a');
}
}
gotoxy(10,12);
puts("Put Stick in Upper Left Corner, Then Press Button.");
do {
keymin=get_joy_position(1);
joymin=get_joy_position(0);
button=get_joy_button(0);
}while (button!=1);
button=0;
delay(400);
gotoxy(10,14);
puts("Put Stick in Lower Right Corner, Then Press Button.");
do {
keymax=get_joy_position(1);
joymax=get_joy_position(0);
button=get_joy_button(0);
}while (button!=1);
delay(400);
return;
}
draw(void)
{
clrscr();
for (wx=0; wx<79; wx++) {
gotoxy(wx,0);
putchar(W);
}
for (wx=0; wx<81; wx++) {
gotoxy(wx,24);
putchar(W);
}
for (wy=3; wy<23; wy++) {
gotoxy(5,wy);
putchar(W);
}
for (wy=3; wy<23; wy++) {
gotoxy(76,wy);
putchar(W);
}
gotoxy(76,23);
putchar(G);
gotoxy(4,13);
putchar(H);
gotoxy(40,13);
printf("%d", level);
echs=random(60);
why=random(20);
echs=echs+10;
why=why+2;
if ((echs == 40) && (why == 13))
{
echs=echs+1;
why=why+1;
}
gotoxy(echs,why);
putchar(K);
x = 4;
y = 13;
a = 76;
b = 23;
return;
}
game(void)
{
key = get_joy_position(1);
joy = get_joy_position(0);
if (snd == 1)
{
sound(random(100)+(key+joy));
}
if (key<(keymin+12)){
ym=-1;
}
if (key>(keymax-12)) {
ym=1;
}
if (joy>(joymax-12)) {
xm=1;
}
if (joy<(joymin+12)) {
xm=-1;
}
moveh();
moveg();
if ((x==a) && (y==b)) {
end();
}
return;
}
moveh(void) /* Human Movement Phase */
{
gotoxy(x,y);
putchar(' ');
x = x + xm;
y = y + ym;
if (x > 79)
{
if ((level!=9) && (pass==1))
{
x=1;
level++;
gotoxy(40,13);
printf("%d", level);
if (level==9)
{
gotoxy(60,13);
putchar(L);
}
else
{
echs=random(60);
why=random(20);
echs=echs+10;
why=why+2;
if (echs==40)
{
echs=echs+1;
}
if (why==13)
{
why=why+1;
}
gotoxy(echs,why);
putchar(K);
pass=0;
}
}
else
{
x=79;
}
}
if (x < 01) {
x=1;}
if (y < 02) {
y=2;}
if (y > 23) {
y = 23;}
if (x == 5) {
if ((y != 2) && (y != 23)){
x = x - xm;
y = y - ym;}
}
if (x == 76) {
if ((y != 2) && (y != 23)){
x = x - xm;
y = y - ym;}
}
if ((x == 40) && (y == 13)){
x = x - xm;
y = y - ym;}
if (level == 9)
{
if ((x == 60) && (y == 13))
{
w=1;
}
}
if (pass==0)
{
if ((x == echs) && (y == why))
{
pass=1;
}
}
ym = 0;
xm = 0;
gotoxy(x,y);
putchar(H);
return;
}
moveg(void) /* Grunda's Movement Phase */
{
gotoxy(a,b);
delay(20);
putchar(' ');
p=random(100+((10-level)*(3)));
if ((a < x) && (p<=80)){
am = 1; }
if ((a > x) && (p<=80)){
am = -1; }
if ((b < y) && (p<=80)){
bm = 1; }
if ((b > y) && (p<=80)){
bm = -1; }
a = a + am;
b = b + bm;
if (a > 79) {
a=79;}
if (a < 01) {
a=1;}
if (b < 02) {
b=2;}
if (b > 23) {
b = 23;}
if (a == 5) {
if ((b != 2) && (b != 23)){
a = a - am;}
if (b==22)
{
b=23;
}
if (b==3)
{
b=2;
}
}
if (a == 76) {
if ((b != 2) && (b != 23)){
a = a - am;}
if (b==22)
{
b=23;
}
if (b==3)
{
b=2;
}
}
if ((a == 40) && (b == 13)){
a = a - am;
b = b - bm;}
if (level==9)
{
if ((a==60) && (b == 13))
{
a=a-am;
b=b-bm;
}
}
if (pass==0)
{
if ((a == echs) && (b == why))
{
a=a-am;
b=b-bm;
}
}
am = 0;
bm = 0;
gotoxy(a,b);
putchar(G);
return;
}
end(void)
{
nosound();
gotoxy(x,y);
puts("*");
for (p=0;p<4;p++)
{
gotoxy(x+p,y);
puts("*");
gotoxy(x-p,y);
puts("*");
gotoxy(x,y);
puts("*");
gotoxy(x+p,y-p);
puts("*");
gotoxy(x-p,y-p);
puts("*");
gotoxy(x,y-p);
puts("*");
gotoxy(x+p,y+p);
puts("*");
gotoxy(x-p,y+p);
puts("*");
gotoxy(x,y+p);
puts("*");
if ((y+p+1)>24)
p=4;
}
if (snd == 1)
{
for (p=0;p<6000;p++)
{
sound(random(200));
}
}
gotoxy(10,10);
puts("Press button 1 to end game.");
gotoxy(10,12);
puts("Press button 2 to begin a new game.");
nosound();
e = 1;
return;
}